<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\model\car;


use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

/**
 * Class CarDate
 * @package app\model\shendeng
 */
class CarDate extends BaseModel
{
    use ModelTrait;

    /**
     * 表主键
     * @var string
     */
    protected $pk = 'id';
    /**
     * 表名
     * @var string
     */
    protected $name = 'car_date';

    /**
     * 关联车辆类型表
     * @return \think\model\relation\HasOne
     */
    public function CarType(){
        return $this->hasOne(CarType::class,'id','type_id')->bind(['type_name']);
    }

    /**
     * id
     * @param $query
     * @param $value
     */
    public function searchIdAttr($query, $value){
        if($value !== ''){
            $query->where('id',$value);
        }
    }

    /**
     * 时间
     * @param \think\Model $query
     * @param $value
     */
    public function searchTimeAttr($query, $value){
        if($value !== ''){
            $time_arr = explode('_',$value);
            $start = strtotime($time_arr[0]);
            $end = strtotime($time_arr[1]);
            $query->whereBetweenTime('book_date',$start,$end);
        }
    }
}
